<?php

    include('functions.php');
    
    $json = curl('http://www.djmaxcn.com/technika/GetLocation.asp');
    
    $state = json_decode($json);
    
    if($state->DATA->ROW === 0) exit('发生错误, 请返回!');
    
    getHead('机台位置/状态');

    echo '<table border="1" width="100%"><tr><th>店名</th><th>数量</th><th>负载</th><th>联网</th><th>统计</th><th>更新时间</th><th>地址</th></tr>';
    foreach($state->DATA->RECORD as $recode) {
        $isMachineConn = $recode->machine_conn == 'off'?'<span style="color:purple;">&nbsp;&nbsp;×&nbsp;&nbsp;</span>':' ';
        $totalPlayTime = floor($recode->TOTAL_PLAYTIME/60);
        switch($recode->chn_word) {
            case '推荐':
                $color = 'green';
                break;
            case '拥挤':
                $color = 'red';
                break;
            case '一般':
                $color = 'orange';
                break;
            default: 
                $color = 'gray';
                break;                  
        }
        
        $total = empty($recode->TOTAL_PLAYERS)?'暂无':"{$recode->TOTAL_PLAYERS}人、{$recode->TOTAL_PLAYCOUNT}次、{$totalPlayTime}分钟";
        
        echo "<tr><td>{$recode->NAME}</td><td>{$recode->MACHINE_COUNT}</td><td style=\"color:{$color};\">{$recode->chn_word}</td><td>{$isMachineConn}</td><td>{$total}</td><td>{$recode->LAST_REFRESH_DATE}</td><td>{$recode->LOCATION}</td></tr>";
    }
    echo '</table>';
    
    getFoot();
